import { createRouter, createWebHashHistory } from 'vue-router'

// 1.导入页面
// 父页面
import Layout from '@/views/layout'
// 子页面
// import Home from '@/views/home'
const Home = () => import('@/views/home')
// 分类页
// import Cate from '@/views/cate'
const Cate = () => import('@/views/cate')
// 商品详情页
const Good = () => import('@/views/good')
// 登录
const Login = () => import('@/views/login')

// 2.配置路由
const routes = [
  {
    path: '/',
    component: Layout,
    children: [
      // 默认跟随父页面一块渲染显示：1.path地址设置为空 2.path地址和父一样
      // 首页
      {
        path: '/',
        component: Home
      },
      // 分类
      {
        path: '/cate/:id',
        component: Cate
      },
      // 商品详情
      {
        path: '/good/:id',
        component: Good
      }
    ]
  },
  {
    path: '/login',
    component: Login
  }
]
// vue2 => new Router()
// vue3 => createRouter()
/**
 * 路由模式修改：
 * vue2 => mode:'hash | history'
 * vue3 => history:createWebHashHistory() | createWebHistory()
 */
const router = createRouter({
  history: createWebHashHistory(),
  routes
})

export default router
